package com.eriloan.easyPage.util;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * <p>Copyright: All Rights Reserved</p>
 * <p>Company: 北京荣之联科技股份有限公司 http://www.ronglian.com</p>
 * <p>Description: 框架核心的 Context </p>
 * <p>Author:Eric Shi/史丙利</p>
 */
public class EasyPageContext{

	/**
	 * 本地线程中的 Request
	 */
	public static ThreadLocal<HttpServletRequest> threadLocalRequest = new ThreadLocal<HttpServletRequest>();
	/**
	 * 本地线程中的 Response
	 */
	public static ThreadLocal<HttpServletResponse> threadLocalResponse = new ThreadLocal<HttpServletResponse>();
	/**
	 * 展示层文件后缀名
	 */
	public static ThreadLocal<String> threadLocalPageSuffix = new ThreadLocal<String>();
	/**
	 * 展示层文件编码
	 */
	public static ThreadLocal<String> threadLocalCharset = new ThreadLocal<String>();
	/**
	 * 模板配置文件路径
	 */
	public static ThreadLocal<String> threadLocalTemplateConfigPath = new ThreadLocal<String>();
	/**
	 * 模板框架类型
	 */
	public static ThreadLocal<String> threadLocalTemplateType = new ThreadLocal<String>();
	/**
	 * 是否支持展示层模板
	 */
	public static ThreadLocal<Boolean> threadLocalIsTemplateView = new ThreadLocal<Boolean>();
	/**
	 * Eclipse页面内容目录
	 */
	public static ThreadLocal<String> threadLocalEclipseContentDirectory = new ThreadLocal<String>();

	/**
	 * 
	 * <br/>Description:获取返回页面的后缀
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @return
	 */
	public String getPageSuffix(){
		return threadLocalPageSuffix.get();
	}

	/**
	 * 
	 * <br/>Description:获取 request
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @return
	 */
	public HttpServletRequest getRequest(){
		return threadLocalRequest.get();
	}

	/**
	 * 
	 * <br/>Description:获取 response
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @return
	 */
	public HttpServletResponse getResponse(){
		return threadLocalResponse.get();
	}

	/**
	 * 
	 * <br/>Description:获取 session
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @return
	 */
	public HttpSession getSession(){
		return threadLocalRequest.get().getSession();
	}

	/**
	 * 
	 * <br/>Description:获取 ServletContext
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @return
	 */
	public ServletContext getServletContext(){
		return threadLocalRequest.get().getSession().getServletContext();
	}

	public String getCharset(){
		return threadLocalCharset.get();
	}

	/**
	 * 
	 * <br/>Description:跳转到一个页面
	 * <p>Author:Eric Shi/史丙利</p>
	 * 
	 * @param path
	 */
	public void doDispatcherForward(String path){
		try{
			threadLocalRequest.get().getRequestDispatcher(path).forward(threadLocalRequest.get(),threadLocalResponse.get());

		}catch(Exception e){
			System.out.println("SE");
			e.printStackTrace();
		}
	}
}
